package pers.jphoebe.quartz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.jphoebe.quartz.entity.*;
import pers.jphoebe.quartz.entity.response.ResponseData;
import pers.jphoebe.quartz.exception.CustomException;
import pers.jphoebe.quartz.service.GoldDataFromJuheService;
import pers.jphoebe.quartz.utils.ResponseDataUtils;

import java.math.BigDecimal;

/**
 * Created by 蒋时华 on 2017/11/2.
 */
@RestController
@RequestMapping("/GsiPrice")
@Api(value = "投资金银条", description = "GsiPriceController")
public class GsiPriceController {

    @Autowired
    private GoldDataFromJuheService goldDataFromJuheService;

    @ApiOperation(value="获取最新金价", notes="获取当前最新金价")
    @PostMapping("/getGoldPrice")
    public ResponseData getGoldPrice(){

        try{
            GoldPrice latestGoldTDPrice = goldDataFromJuheService.getLatestGoldTDPrice();
            return ResponseDataUtils.success(latestGoldTDPrice);
        }catch (CustomException e){
            return ResponseDataUtils.error(e.getErrorCode());
        }
    }

    @ApiOperation(value = "获取最新银价", notes = "获取当前最新银价")
    @PostMapping("/getSilverPrice")
    public ResponseData getSilverPrice(){

        try{
            SilverPrice latestSilvetyTDPrice = goldDataFromJuheService.getLatestSilvetyTDPrice();
            return ResponseDataUtils.success(latestSilvetyTDPrice);
        }catch (CustomException e){
            return ResponseDataUtils.error(e.getErrorCode());
        }

    }

    @ApiOperation(value = "计算金价价格", notes = "计算供货价、零售价、银行中收")
    @PostMapping("/getGoldPriceTotal")
    public ResponseData getGoldPriceTotal(@RequestBody @ApiParam(name="投资金对象",value="传入json格式",required=true) GsiGoldPrice gsiPrice){

        if(gsiPrice==null){
            gsiPrice = new GsiGoldPrice();
        }
        try{
            GsiGoldPrice latestGoldTDPriceTotal = goldDataFromJuheService.getLatestGoldTDPriceTotal(gsiPrice);
            return ResponseDataUtils.success(latestGoldTDPriceTotal);
        }catch (CustomException e){
            return ResponseDataUtils.error(e.getErrorCode());
        }
    }

    @ApiOperation(value = "计算银价价格", notes = "计算供货价、零售价、银行中收")
    @PostMapping("/getSilverPriceTotal")
    public ResponseData getSilverPriceTotal(@RequestBody @ApiParam(name="投资银对象",value="传入json格式",required=true) GsiSilverPrice gsiPrice){

        if(gsiPrice==null){
            gsiPrice = new GsiSilverPrice();
        }
        try{
            GsiSilverPrice latestSilvetyTDPriceTotal = goldDataFromJuheService.getLatestSilvetyTDPriceTotal(gsiPrice);
            return ResponseDataUtils.success(latestSilvetyTDPriceTotal);
        }catch (CustomException e){
            return ResponseDataUtils.error(e.getErrorCode());
        }

    }


}
